package com.dapeis.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.entity.Example.Criteria;
import cn.jpush.api.common.resp.IRateLimiting;

import com.ag.dao.DBService;
import com.ag.dao.IDao;
import com.dapeis.dao.ICollocationInformationExtMapper;
import com.dapeis.dao.ICollocationInformationMapper;
import com.dapeis.domain.CollocationInformation;
import com.dapeis.domain.ext.CollocationInformationExt;

@Service
public class CollocationInformationService extends
	DBService<CollocationInformation> {
    @Resource
    ICollocationInformationMapper mapper;

    @Resource
    ICollocationInformationExtMapper collocationInformationExtMapper;

    @Override
    protected IDao<CollocationInformation> getIDao() {
	return mapper;
    }

    /**
     * 查询是否存在 true 存在,false 不存在
     * 
     * @param collocationId
     * @return
     */
    public boolean isExist(Integer collocationId) {
	if (null != getCollocaitonInformationByCollocationId(collocationId)) {
	    return true;
	}
	return false;
    }

    /**
     * 查询是否存在对象 null 不存在,否为存在
     * 
     * @param collocationId
     * @return
     */
    public CollocationInformation getCollocaitonInformationByCollocationId(
	    Integer collocationId) {
	Example example = new Example(CollocationInformation.class);
	Criteria criteria = example.createCriteria();
	criteria.andEqualTo(CollocationInformation.PROPERTY_COLLOCATION_ID,
		collocationId);
	List<CollocationInformation> informations = mapper
		.selectByExample(example);
	if (!informations.isEmpty()) {
	    return informations.get(0);
	}
	return null;
    }

    public ICollocationInformationExtMapper getInforExtMapper() {
	return collocationInformationExtMapper;
    }
}
